﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Demo
{
    public partial class Show : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //判断是否登陆进来的 
            /** 注释起点
            try
            {
                TextBox ty = (TextBox)Page.PreviousPage.FindControl("TextBox1");
              
            }
            catch (Exception ex)
            {
               // Response.Write(ex);
                Response.Write("请先登陆，登陆后再进行操作!" + "（错误信息：" + ex + ")");
                Response.End();
            }
          注释末端  */
            

/** 注释起点
            //第1步 . 建立数据连接对象
            SqlConnection con = new SqlConnection();
            con.ConnectionString = @"Server =.\JSON; Database =Data; Trusted_Connection = True;";
            /*con.ConnectionString = @"Server=.\sqlexpress;Database=Student;User Id=sa;
 Password=123456;";//点号代表当前服务器名 
            //第二步   建立数据操作对象
            string sqlSelect = "select StudentId,Name,Password from StudentList";
            con.Open();
            SqlCommand cmd = new SqlCommand(sqlSelect, con);
            con.Close();
            //第三步   数据适配器里显示访问
            SqlDataAdapter dap = new SqlDataAdapter();
            dap.SelectCommand = cmd;
            //第四步   完成数据填充
            DataTable dt = new DataTable("StudentList");
            dap.Fill(dt);
            //第五步  将数据显示在web页面，通过数据绑定空间Gridview
            GridView1.DataSource = dt;
            GridView1.DataBind();
            
        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string sqlstr = "delete from StudentList where StudentID='" + GridView1.DataKeys[e.RowIndex].Value.ToString() + "'";
            //第1步 . 建立数据连接对象
            SqlConnection con = new SqlConnection();
            SqlCommand cmd = new SqlCommand(sqlstr, con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
            //第三步   数据适配器里显示访问
            SqlDataAdapter dap = new SqlDataAdapter();
            dap.SelectCommand = cmd;
            //第四步   完成数据填充
            DataTable dt = new DataTable("StudentList");
            dap.Fill(dt);
            //第五步  将数据显示在web页面，通过数据绑定空间Gridview
            GridView1.DataSource = dt;
            GridView1.DataBind();
       

     注释末端 */
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Response.Redirect("TeaAddStuList.aspx");
        }
        


      
    }
}